package dao.impl;

import dao.SupplierDao;
import entity.Supplier;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import utils.DruidUtils;

import java.util.List;

public class SupplierDaoImpl implements SupplierDao {
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(DruidUtils.getDataSource());

    @Override
    public List<Supplier> selectAllSuppliers() {
        String sql = "select* from supplier";
        List<Supplier> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Supplier.class));
        return query;
    }

    @Override
    public void addSupplier(Supplier supplier) {
        String sql = " insert into supplier values (?,?,?,?)";
        jdbcTemplate.update(sql,supplier.getSuid(),supplier.getSuname(),supplier.getSuaddress(),supplier.getSutel());
    }
}
